#include <func.h>

int main(int argc,char *argv[])
{
    ARGS_CHECK(argc,3);
    int fdw=open(argv[1],O_WRONLY);
    int fdr=open(argv[2],O_RDONLY);
    fd_set rdset;
    char buf[4096]={0};
    while(1)
    {
        FD_ZERO(&rdset);
        FD_SET(STDIN_FILENO,&rdset);
        FD_SET(fdr,&rdset);
        select(fdr+1,&rdset,NULL,NULL,NULL);
        if(FD_ISSET(STDIN_FILENO,&rdset))
        {
            memset(buf,0,sizeof(buf));
            ssize_t sret=read(STDIN_FILENO,buf,sizeof(buf));
            if(sret==0)
            {
                printf("close\n");
                break;
            }  
            write(fdw,buf,strlen(buf));
        }
        if(FD_ISSET(fdr,&rdset))
        {
            memset(buf,0,sizeof(buf));
            ssize_t sret=read(fdr,buf,sizeof(buf));
            if(sret==0)
            {
                printf("game over\n");
                break;
            }
            printf("sret=%ld buf=%s\n",sret,buf);
        }
    

    }
    close(fdr),close(fdw);
    return 0;
}

